﻿using System.IO.Compression;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;

namespace ELportal.Common.Extensions;

public static class ServicesExtensions
{
	public static IServiceCollection AddBrotliCompression(this IServiceCollection services, CompressionLevel? compressionLevel)
	{
		services.AddResponseCompression(options =>
		{
			options.Providers.Clear();
			options.Providers.Add<BrotliCompressionProvider>();

			options.EnableForHttps = true;
		})
		.Configure<BrotliCompressionProviderOptions>(options => options.Level = compressionLevel ?? CompressionLevel.NoCompression);

		return services;
	}
}
